import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static int n;
    public static List<Integer> list = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        dfs(arr, 0, 0, 0);

        int ret = Integer.MAX_VALUE;
        for (int num : list) {
            ret = Math.min(ret, n - num);
        }
        System.out.println(ret);

        sc.close();
    }

    public static void dfs(int[] arr, int index, int lastNum, int len) {
        list.add(len);
        if (index == n) {
//            list.add(len);
            return;
        }


        for (int i = index; i < n; i++) {
            if (index == 0 || lastNum == firstNum(arr[i])) {
                dfs(arr, i + 1, arr[i] % 10, len + 1);
            }
        }
    }

    /**
     * 找到 num 的第一位数字
     * @param num
     * @return
     */
    public static int firstNum(int num) {
        String str = num + "";
        char first = str.charAt(0); //第一个字符
        return Integer.parseInt(Character.toString(first));
    }
}
